import Vue from 'vue'
import Router from 'vue-router'
/* 用户前端部分 */
import Address from '@/components/Address'
import Housing from '@/components/Housing'
import Index from '@/components/Index'
import Login from '@/components/Login'
import Logout from '@/components/Logout'
// 主页
import Main from '@/components/Main'
// 动态
import News from '@/components/News'
import Regist from '@/components/Regist'
//商家服务
import Buyservice from '@/components/Buyservice'
import Service from '@/components/Service'
import Serviceall from '@/components/Serviceall'
import Servicecommunity from '@/components/Servicecommunity'
import Serviceorder from '@/components/Serviceorder'
import Servicetype from '@/components/Servicetype'
import Servicetypelist from '@/components/Servicetypelist'
import Servicedetail from '@/components/Servicedetail'
//活动
import Activity from '@/components/Activity'
// 账号相关
import Account from '@/components/Account'
import ChgHeadImg from '@/components/ChgHeadImg'
import ChgPwd from '@/components/ChgPwd'
import ComplaintAdvice from '@/components/ComplaintAdvice'
import MyNews from '@/components/MyNews'
import mySecondHand from '@/components/MySecondHand'
import mySecondHandOrder from '@/components/MySecondHandOrder'
import mySecondHandOrder1 from '@/components/MySecondHandOrder1'
import newSecondHand from '@/components/NewSecondHand'
import secondHand from '@/components/SecondHand'
import secondHandDetail from '@/components/SecondHandDetail'
import secondHandManage from '@/components/SecondHandManage'
import secondHandOrderManage from '@/components/SecondHandOrderManage'
import UserInfo from '@/components/UserInfo'
/* 后台管理部分 */
import ActivityManage from '@/components/ActivityManage'
import addCommunity from '@/components/addCommunity'
import Addservice from '@/components/Addservice'
import Admin from '@/components/Admin'
import AdminComplaintAdvice from '@/components/AdminComplaintAdvice'
import AdminInfo from '@/components/AdminInfo'
import HousingCheck from '@/components/HousingCheck'
import Log from '@/components/Log'
import Merchantorder from '@/components/Merchantorder'
import Merchantservice from '@/components/Merchantservice'
import NewsManage from '@/components/NewsManage'
import Personalmerchant from '@/components/Personalmerchant'
import Qualificationreview from '@/components/Qualificationreview'
import RoleManage from '@/components/RoleManage'
import Unacceptorder from "@/components/Unacceptorder"
import UserManage from '@/components/UserManage'

import InternalMessage from '@/components/InternalMessage'
import Message from '@/components/Message'
import MyMessage from '@/components/MyMessage'
import PostMess from '@/components/PostMess'

//网上超市
import Goods from '@/components/Goods'
import GoodsDetails from '@/components/GoodsDetails'
import GoodsList from '@/components/GoodsList'
import ShoppingBag from '@/components/ShoppingBag'
import GoodsDetailsInfo from '@/components/GoodsDetailsInfo'
import test from '@/components/test'

import Convenience_payment from '@/components/Convenience_payment'
//这里如果自动填写的话，它会给你加上Src,那玩意
/* 水电气 */
/* 水电气 */
import Convenience_payment_water from '@/components/Convenience_payment_water'
// import Convenience_payment_property from '@/components/Convenience_payment_property.vue'

// import Convenience_payment_property from '@/components/Convenience_payment_property.vue'

import Convenience_payment_electricity from '@/components/Convenience_payment_electricity'
import Convenience_payment_electricity_history from '@/components/Convenience_payment_electricity_history'

import Convenience_payment_naturalgas from '@/components/Convenience_payment_naturalgas.vue'
import Convenience_payment_naturalgas_history from '@/components/Convenience_payment_naturalgas_history'
import Convenience_payment_naturalgas_money from '@/components/Convenience_payment_naturalgas_money'


import Convenience_payment_water_history from '@/components/Convenience_payment_water_history'
import Convenience_payment_water_money from '@/components/Convenience_payment_water_money'
import Convenience_payment_water_ChargeMoney from '@/components/Convenience_payment_water_ChargeMoney'

//疫情服务
import EpidemicView from '@/components/EpidemicView.vue'
import HealthView from '@/components/HealthView.vue'
import Epidemic_record from '@/components/Epidemic_record.vue'
import Epidemic_relief from '@/components/Epidemic_relief.vue'
import Epidemic_Special_Things from '@/components/Epidemic_Special_Things.vue'

//后台
import Epidemic_Special_Things_Backstage from '@/components/Epidemic_Special_Things_Backstage.vue'
import Epidemic_reservationdata from '@/components/Epidemic_reservationdata.vue'
//社区资讯
import InformationView from '@/components/InformationView.vue'
import Notice_announcement from '@/components/Notice_announcement.vue'
import ImportantMatters from '@/components/ImportantMatters.vue'
import Epidemic_situation from '@/components/Epidemic_situation.vue'
import Hot_search from '@/components//Hot_search.vue'
//智慧停车里的爱车子路由
import Park_LoveCar_gsaup from '@/components/Park_LoveCar_gsaup'
import Park_LoveCar_maintain from '@/components/Park_LoveCar_maintain'
import Park_LoveCar_wash from '@/components/Park_LoveCar_wash'

//停车服务的
import Park from '@/components/Park'
import Park_Home from '@/components/Park_Home'
import Park_LoveCar from '@/components/Park_LoveCar'
import Park_My from '@/components/Park_My'
import Park_Home_Parking from '@/components/Park_Home_Parking'
import Park_ChangeMoney from '@/components/Park_ChangeMoney'
import Park_My_Order from '@/components/Park_My_Order'
import Park_My_Serve from '@/components/Park_My_Serve'
import Park_My_Message from '@/components/Park_My_Message'
import Park_My_Money from '@/components/Park_My_Money'

//引入支付组件
// 引入组件
import payIndex from '@/components/payIndex'
import PayOrders from '@/components/PayOrders'
import Download from '@/components/Download'
import Success from '@/components/Success'


Vue.use(Router)

let router = new Router({
  routes: [
    {
      path: '/',
      component: Index,
      children: [
        {
          path: '/',
          component: Main
        },
        {
          path: 'news',
          component: News
        },
        {
          path:'activity',
          component: Activity
        },
        {
          path:'message',
          component:Message, //前台消息中心
          children:[
            {
              path:"myMessage",
              component:MyMessage
            }
          ]
        },
        {
          path: 'account',
          component: Account,
          children: [
            {
              path: "/",
              component: UserInfo
            },
            {
              path: "housing",
              component: Housing
            },
            {
              path: "complaintAdvice",
              component: ComplaintAdvice
            },
            {
              path: "address",
              component: Address
            },
            {
              path: 'chgHeadImg',
              component: ChgHeadImg
            },
            {
              path: 'chgPwd',
              component: ChgPwd
            },
            {
              path: 'myNews',
              component: MyNews
            },
            {
              path: 'mySecondHand',
              component: mySecondHand
            },
            {
              path: 'mySecondHandOrder',
              component: mySecondHandOrder
            },
            {
              path: 'mySecondHandOrder1',
              component: mySecondHandOrder1
            }
          ]
        },


        // 商家服务 和account（个人中心）同级
        // {
        //   path: 'secondHand',
        //   component: secondHand,
        //   children: [
        //     {
        //       path: 'chgHeadImg',
        //       component: ChgHeadImg
        //     }

        //   ]
        // },

        //网上超市
        {
          path: 'goods',
          component: Goods,
        },
        {
          path: 'GoodsDetails',
          name: "GoodsDetails",
          component: GoodsDetails,
        },
        {
          path: 'GoodsList',
          component: GoodsList,
        },
        {
          path: 'GoodsDetailsInfo',
          name: 'GoodsDetailsInfo',
          component: GoodsDetailsInfo,
        },
        {
          path: 'ShoppingBag',
          component: ShoppingBag
        },
        {
          path: 'test',
          component: test
        },

        //支付
        {
          path: '/orders',
          name:'orders',
          component: PayOrders
        },
        {
            path: '/download',
            name: 'download',
            component: Download
        },
        {
            path: '/success',
            name: 'success',
            component: Success
        },
        {
          path: '/payIndex',
          name: 'payIndex',
          component: payIndex
        },




        {
          path: 'secondHandDetail',
          component: secondHandDetail,

        },
        {
          path: 'newSecondHand',
          component: newSecondHand,

        },

        {
          path: 'login',
          component: Login
        },
        {
          path: '/service',
          component: Service,
          children: [
            {
              path: '/',
              component: Servicecommunity
            },
            {
              path: '/servicecommunity',
              name: 'Servicecommunity',
              component: Servicecommunity
            },
            {
              path: '/servicetype',
              name: 'Servicetype',
              component: Servicetype
            },
             // 通过类型找服务
            {
              path:'/servicetypelist',
              name:'Servicetypelist',
              component: Servicetypelist
            },
            {
              path: '/serviceorder',
              name: 'Serviceorder',
              component: Serviceorder
            },
            {
              path: '/serviceall',
              name: 'Serviceall',
              component: Serviceall
            },
            {
              path:'/servicedetail',
              name:'Servicedetail',
              component: Servicedetail
            },
            {
              path:'/buyservice',
              name:'Buyservice',
              component: Buyservice
            }

          ]
        },
        {
			//便民缴费
		  path:'/Convenience_payment',
		  component: Convenience_payment,
		  children:[
			  {
				 path:'/Convenience_payment_water',
				 component: Convenience_payment_water,
				 children:[
					 {
						 path:'/Convenience_payment_water_history',
						 component:Convenience_payment_water_history
					 },
					 {
						 path:'/Convenience_payment_water_money',
						 component:Convenience_payment_water_money
					 },
					 {
						 path:'/Convenience_payment_water_ChargeMoney',
						 component:Convenience_payment_water_ChargeMoney
					 },
				 ]
			  },
			  {
				 path:'/Convenience_payment_electricity',
				 component:Convenience_payment_electricity,
				 children:[
					 {
						 path:'/Convenience_payment_electricity_history',
						 component:Convenience_payment_electricity_history
					 },
					 {
						 path:'/Convenience_payment_electricity_money',
						 component:Convenience_payment_water_money
					 },
					 {
						 path:'/Convenience_payment_water_ChargeMoney',
						 component:Convenience_payment_water_ChargeMoney
					 },
				 ],
				 children:[
					 {
						 path:'/Convenience_payment_electricity_history',
						 component:Convenience_payment_electricity_history
					 },
					 {
						 path:'/Convenience_payment_electricity_money',
						 component:Convenience_payment_water_money
					 },
					 {
						 path:'/Convenience_payment_water_ChargeMoney',
						 component:Convenience_payment_water_ChargeMoney
					 },
				 ]
			  },
			  {
				 path:'/Convenience_payment_naturalgas',
				 component:Convenience_payment_naturalgas,
				 children:[
					 {
						 path:'/Convenience_payment_naturalgas_history',
						 component:Convenience_payment_naturalgas_history
					 },
					 {
						 path:'/Convenience_payment_naturalgas_money',
						 component:Convenience_payment_naturalgas_money
					 },
					 {
						 path:'/Convenience_payment_water_ChargeMoney',
						 component:Convenience_payment_water_ChargeMoney
					 },
				 ]

			  },
			 /* {
				 path:'/Convenience_payment_property',
				 component:Convenience_payment_property
			  }, */

		  ]
		},
		{
			//停车服务系列
			path:'/Park',
			component: Park,
			children:[
				{
					path:'/Park_Home',
					component:Park_Home,
					children:[
						{
							path:'/Park_Home_Parking',
							component:Park_Home_Parking
						},
						{
							path:'/Park_ChangeMoney',
							component:Park_ChangeMoney
						},
					]
				},
				{
					path:'/Park_LoveCar',
					component:Park_LoveCar,
          children:[
            {//加油推荐
              path: '/Park_LoveCar_gsaup',
              component: Park_LoveCar_gsaup
            },
            {//车辆保养推荐
              path: '/Park_LoveCar_maintain',
              component: Park_LoveCar_maintain
            },
            {//洗车推荐
              path: '/Park_LoveCar_wash',
              component: Park_LoveCar_wash
            },
          ]
				},
				{
					path:'/Park_My',
					component:Park_My,
					children:[
						{
							path:'/',
							component:Park_My_Message
						},{
							path:'/Park_My_Money',
							component:Park_My_Money
						},
					]
				},
				{
					//我的订单
					path:'/Park_My_Order',
					component:Park_My_Order
				},
				{
					//我的服务
					path:'/Park_My_Serve',
					component:Park_My_Serve

				},

			]

		},
    //疫情服务
        {
          path: '/epidemic',
          component: EpidemicView,
          children: [{
              path: '/health',
              component: HealthView,
            },
            {
              path: '/epidemic_record',
              component: Epidemic_record,
            },
            {
              path: '/epidemic_relief',
              component: Epidemic_relief,
            },
            {
              path: '/epidemic_reservationdata',
              component: Epidemic_reservationdata,
            },
            {
              path: '/epidemic_special_things_backstage',
              component: Epidemic_Special_Things_Backstage,
            },
            {
              path: '/epidemic_special_things',
              component: Epidemic_Special_Things,
            }
          ]
        },
        //社区公告
        {
        	path: '/information',
        	component: InformationView,
        	children:[
        		{
        			path: '/importantmatters',
        			component: ImportantMatters,
        		},
        		{
        			path: '/activity',
        			component: Notice_announcement,
        		},
        		{
        			path: '/epidemic_situation',
        			component: Epidemic_situation,
        		},
        		{
        			path: '/hot_search',
        			component: Hot_search,
        		},
        	]
        },
        {
          path: '/regist',
          component: Regist
        },
        {
          path: '/login',
          component: Login
        },
        {
          path: '/regist',
          component: Regist
        },
        {
          path: '/login',
          component: Login
        },
      ]
    },
    //后台管理
//和index同级
    {
      path: "/admin",
      component: Admin,
      children: [
        {
          path: "/",
          component: AdminInfo
        },
        {
          path: 'qualificationreview',
          component: Qualificationreview,

        },
        {
          path: 'merchantorder',
          // name: 'Merchantorder',
          component: Merchantorder
        },
        {
          path: 'merchantservice',
          // name: 'Merchantorder',
          component: Merchantservice
        },
        {
          path: 'personalmerchant',
          component: Personalmerchant
        },
        {
          path: 'addservice',
          component: Addservice
        },
        {
          path:'unacceptorder',
          component:Unacceptorder
        },
        {
          path: "adminComplaintAdvice",
          component: AdminComplaintAdvice
        },
        {
          path: "addCommunity",
          component: addCommunity
        },
        {
          path: "housingCheck",
          component: HousingCheck
        },
        {
          path: "userManage",
          component: UserManage
        },
        {
          path:"internalMessage", //后台站内信
          component:InternalMessage,
          children:[
            {
              path:"postMess",
              component:PostMess
            },
            {
              path:"myMessage",
              component:MyMessage
            }
          ]
        },
         { path: "activityManage",
          component: ActivityManage,
        },
        {
          path: "newsManage",
          component: NewsManage
        },
        {
          path: "roleManage",
          component: RoleManage
        },
        {
          path: "secondHandManage",
          component: secondHandManage
        },
        {
          path: "secondHandOrderManage",
          component: secondHandOrderManage
        },

        {
          path: "log",
          component: Log
        }
      ]
    },
    {
      path: '/logout',
      component: Logout
    }
  ],
  mode:"history"
})

/**
 * 解决js代码跳转路由时重复跳转同一个页面产生的报错问题
 */
//获取原型对象上的push函数
const originalPush = Router.prototype.push
//修改原型对象中的push方法
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}





/**
 * 前置钩子
 */
router.beforeEach((to,from,next)=>{
//如果是访问登录页，直接放行
 if(to.path=='/' || to.path=='/login' || to.path=='/regist'){
 next();
  return;
 }

 //否则判断本地是否保存了user对象，没有说明没登录或已关闭过路由器
 let token = sessionStorage.getItem("token");
 if(token){
  //有token信息放行
  next();
 }else{
  //没有去登录页面
  next("/login");
 }

});



export default router
